home *** CD-ROM | disk | FTP | other *** search
/ Delphi Magazine Collection 2001 / Delphi Magazine Collection 20001 (2001).iso / DISKS / Issue61 / Construc / TDM61L.DPR < prev    next >
Encoding:
Text File  |  2000-08-06  |  2.9 KB  |  138 lines

  1. program TDM61;
  2. {$APPTYPE CONSOLE}
  3. uses
  4.   SysUtils, MMSystem;
  5.  
  6.   // resourcestring
  7.  
  8.   function CaptionMaker1(Str: String): String;
  9.   { stack: 256 (arg) + 256 (local) + 256 (result) bytes }
  10.   var
  11.     i: Integer;
  12.     Tmp: String;
  13.   begin
  14.     Tmp := Str; // initial copy
  15.     for i:=1 to Length(Str) do
  16.       if (i = 1) or (Str[i-1] = #32) then
  17.         Tmp[i] := UpCase(Str[i])
  18.       else
  19.         Tmp[i] := Str[i];
  20.     Result := Tmp;
  21.   end;
  22.  
  23.   function CaptionMaker2(Str: String): String;
  24.   { stack: 256 (arg) + 256 (result) bytes }
  25.   var
  26.     i: Integer;
  27.   begin
  28.     for i:=1 to Length(Str) do
  29.       if (i = 1) or (Str[i-1] = #32) then
  30.         Str[i] := UpCase(Str[i]);
  31.     Result := Str
  32.   end;
  33.  
  34.   function CaptionMaker3(const Str: String): String;
  35.   { stack: 256 (result) bytes }
  36.   var
  37.     i: Integer;
  38.   begin
  39.     Result := Str; // initial copy
  40.     for i:=1 to Length(Str) do
  41.       if (i = 1) or (Str[i-1] = #32) then
  42.         Result[i] := UpCase(Str[i])
  43.   end;
  44.  
  45.   procedure CaptionMaker4(var Str: String);
  46.   var
  47.     i: Integer;
  48.   begin
  49.     for i:=1 to Length(Str) do
  50.       if (i = 1) or (Str[i-1] = #32) then
  51.         Str[i] := UpCase(Str[i])
  52.   end;
  53.  
  54.   function CaptionMaker5(var Str: String): PString;
  55.   var
  56.     i: Integer;
  57.   begin
  58.     for i:=1 to Length(Str) do
  59.       if (i = 1) or (Str[i-1] = #32) then
  60.         Str[i] := UpCase(Str[i]);
  61.     Result := @Str
  62.   end;
  63.  
  64.   function ReadFile(const FileName: String): String;
  65.   var
  66.     f: Text;
  67.     Line,Str: String;
  68.   begin
  69.     Str := '';
  70.     Assign(f,FileName);
  71.     Reset(f);
  72.     while not eof(f) do
  73.     begin
  74.       readln(f,Line);
  75.       Str := Str + #13#10 + Line { re-allocate Str }
  76.     end;
  77.     Result := Str
  78.   end;
  79.  
  80. var
  81.   Str: String;
  82.   Str2: String;
  83.   EndTime: Cardinal;
  84.   Reps: Integer;
  85.   Ch: WideChar;
  86. var
  87.   X: Array[0..42] of Char;
  88.   Y: PChar;
  89. begin
  90.   X := 'this is a null-terminated string';
  91.   Y := X; { pointer Y points to X now }
  92.   Y[0] := 'T';
  93.   writeln(X);
  94.  
  95.   Str := 'this is a short string to test';
  96.   Ch := Chr(256 + 32);
  97.   writeln(Ord(Ch));
  98.   Str2 := '';
  99. //SetLength(Str2,1);
  100. //if Str2[11] = #32 then writeln('access violation');
  101.  
  102.   Reps := 0;
  103.   EndTime := TimeGetTime + 100;
  104.   repeat
  105.     Inc(Reps);
  106.     Str2 := CaptionMaker1(Str);
  107.   until TimeGetTime > EndTime;
  108.   writeln('1: ',Reps);
  109.   Reps := 0;
  110.   EndTime := TimeGetTime + 100;
  111.   repeat
  112.     Inc(Reps);
  113.     Str2 := CaptionMaker2(Str);
  114.   until TimeGetTime > EndTime;
  115.   writeln('2: ',Reps);
  116.   Reps := 0;
  117.   EndTime := TimeGetTime + 100;
  118.   repeat
  119.     Inc(Reps);
  120.     Str2 := CaptionMaker3(Str);
  121.   until TimeGetTime > EndTime;
  122.   writeln('3: ',Reps);
  123.   Reps := 0;
  124.   EndTime := TimeGetTime + 100;
  125.   repeat
  126.     Inc(Reps);
  127.     CaptionMaker4(Str);
  128.   until TimeGetTime > EndTime;
  129.   writeln('4: ',Reps);
  130.   Reps := 0;
  131.   EndTime := TimeGetTime + 100;
  132.   repeat
  133.     Inc(Reps);
  134.     Str2 := CaptionMaker5(Str)^;
  135.   until TimeGetTime > EndTime;
  136.   writeln('5: ',Reps);
  137.   readln
  138. end.